#! /usr/bin/env python
# -*- coding: utf-8 -*-
from uiautomator import AutomatorDevice
from uiautomator import Adb as adb
from GameYYS.YYS import YYS
import random
import time
'''
device = AutomatorDevice(serial='3HX0116901000092')
device.screen.on()
device.click(1282,1203)
low = random.randint(97,122)
up  = random.randint(65,90)
num = random.randint(48,57)
print "百花花道%c%c%c" % (up,low,num)
device.watcher('cancel').when(text=u'取消').click(text=u'取消')
'''
low = random.randint(65,90)-65+29
up  = random.randint(65,90)-65+29
num = random.randint(48,57)-48+7
# 在ascill下 48-57是数字，65-90 是大写字母，97-122是小写字母
# 在android系统下 7-16 是数，29-54 是大写字母
def writestr(str):
    print str
    for i in range(0,len(str)):
        if ord(str[i]) in range(48,57):
            num = ord(str[i])-48+7
            cmd_line = "shell input keyevent %d" % num
        if str[i].islower():
            num = ord(str[i])-97+29
            cmd_line = "shell input keyevent %d" % num
        if str[i].isupper():
            num = ord(str[i])-65+29
            cmd_line = "shell input keyevent %d" % num
        if str[i].isspace():
            cmd_line = "shell input keyevent 62"
        if str[i] == ",":
            cmd_line = "shell input keyevent 55"
        if str[i] == ".":
            cmd_line = "shell input keyevent 56"
        de = adb(serial='ETM7N16A06000091')
        de.cmd(cmd_line)
        time.sleep(0.1)
    pass


#press home key
if __name__ =='__main__':
    writestr("Hello, world.")